home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / commands.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  2KB  |  80 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Execute shell commands via os.popen() and return status, output.
  5.  
  6. Interface summary:
  7.  
  8.        import commands
  9.  
  10.        outtext = commands.getoutput(cmd)
  11.        (exitstatus, outtext) = commands.getstatusoutput(cmd)
  12.        outtext = commands.getstatus(file)  # returns output of "ls -ld file"
  13.  
  14. A trailing newline is removed from the output string.
  15.  
  16. Encapsulates the basic operation:
  17.  
  18.       pipe = os.popen(\'{ \' + cmd + \'; } 2>&1\', \'r\')
  19.       text = pipe.read()
  20.       sts = pipe.close()
  21.  
  22.  [Note:  it would be nice to add functions to interpret the exit status.]
  23. '''
  24. __all__ = [
  25.     'getstatusoutput',
  26.     'getoutput',
  27.     'getstatus']
  28.  
  29. def getstatus(file):
  30.     '''Return output of "ls -ld <file>" in a string.'''
  31.     import warnings as warnings
  32.     warnings.warn('commands.getstatus() is deprecated', DeprecationWarning, 2)
  33.     return getoutput('ls -ld' + mkarg(file))
  34.  
  35.  
  36. def getoutput(cmd):
  37.     '''Return output (stdout or stderr) of executing cmd in a shell.'''
  38.     return getstatusoutput(cmd)[1]
  39.  
  40.  
  41. def getstatusoutput(cmd):
  42.     '''Return (status, output) of executing cmd in a shell.'''
  43.     import os as os
  44.     pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
  45.     text = pipe.read()
  46.     sts = pipe.close()
  47.     if sts is None:
  48.         sts = 0
  49.     
  50.     if text[-1:] == '\n':
  51.         text = text[:-1]
  52.     
  53.     return (sts, text)
  54.  
  55.  
  56. def mk2arg(head, x):
  57.     warnpy3k = warnpy3k
  58.     import warnings
  59.     warnpy3k('In 3.x, mk2arg has been removed.')
  60.     import os
  61.     return mkarg(os.path.join(head, x))
  62.  
  63.  
  64. def mkarg(x):
  65.     warnpy3k = warnpy3k
  66.     import warnings
  67.     warnpy3k('in 3.x, mkarg has been removed.')
  68.     if "'" not in x:
  69.         return " '" + x + "'"
  70.     s = ' "'
  71.     for c in x:
  72.         if c in '\\$"`':
  73.             s = s + '\\'
  74.         
  75.         s = s + c
  76.     
  77.     s = s + '"'
  78.     return s
  79.  
  80.